-
-
Notifications
You must be signed in to change notification settings - Fork 469
Docs: Add error handling section to submission handling docs #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
if (response.isError) { | ||
// Username is taken, return an error for the username field | ||
return 'Username is already taken!' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This says
return an error for the username field
but the error seems to go to the Form not to the Field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! The comment is kind of redundant now. I'll remove it!
onSubmit: async ({ value }) => { | ||
// If an error happens, they are accessible through | ||
// `createAccountMutation.error` | ||
await createAccountMutation.mutateAsync(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promoting "mutateAsync" here feels off:
you should almost always use
mutate
– https://tkdodo.eu/blog/mastering-mutations-in-react-query#mutate-or-mutateasync
await createAccountMutation.mutateAsync(value) | |
createAccountMutation.mutate(value, { | |
onSuccess: () => { | |
// handle success by navigate to another route e.g. | |
} | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the thought process behind it:
- Is
mutate
synchronous? If not,onSubmit
would finish immediately andisSubmitting
would flashtrue
for a moment - Error handling informs TSF about
isSubmitSuccessful
, which would cause a disconnect ifmutate
errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then this seems like one of those exceptions to not prefere mutate
over mutateAsync
;-)
It's perfect as it is, thanks for clarifying!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you reckon this should be mentioned somewhere? I assume there's lots of users combining Tanstack Form with TansStack Query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some explenation here: https://tanstack.com/form/latest/docs/reference/type-aliases/baseformstate#issubmitting
I think it would be good to mention it on the "Submission Handling"-Page as well as it clears up a lot of questions.
Signed-off-by: Pascal Küsgen <pascalkuesgen@gmail.com>
docs: expand submission handling in angular
This PR adds some code snippets to get users started on the three common types of errors:
The user errors are implemented using form / field validators (with links to the validation guide page). The Server error example is implemented using TanStack Query.